<?php
/**
 * Created by PhpStorm.
 * User: zhangrxiang
 * Date: 2016/9/23
 * Time: 9:40
 */

for ($i = 30; $i < 230 ; $i++){
    //echo chr($i);
}

function unichr($dec)
{
    if ($dec < 0x80)
    {
        $utf = chr($dec);
    }
    else if ($dec < 0x0800)
    {
        $utf = chr(0xC0 + ($dec >> 6));
        $utf .= chr(0x80 + ($dec & 0x3f));
    }
    else if ($dec < 0x010000)
    {
        $utf = chr(0xE0 + ($dec >> 12));
        $utf .= chr(0x80 + (($dec >> 6) & 0x3f));
        $utf .= chr(0x80 + ($dec & 0x3f));
    }
    else if ($dec < 0x200000)
    {
        $utf = chr(0xF0 + ($dec >> 18));
        $utf .= chr(0x80 + (($dec >> 12) & 0x3f));
        $utf .= chr(0x80 + (($dec >> 6) & 0x3f));
        $utf .= chr(0x80 + ($dec & 0x3f));
    }
    else
    {
        die("UTF-8 character size is more than 4 bytes");
    }

    return $utf;
}

echo unichr(0x263A);
echo unichr(0x013A);

$var = 0x1111;
echo $var;


var_dump(0 == 'all'); // TRUE, take care
if(0){
    echo 11;
}
if('q' == 0){
    echo '11';
}
if(0 == ''){
    echo '11';
    var_dump((bool)'1212');
}
if(0 == 'a'){
    echo '11';
}



function arraySortByElements($array2sort,$sortField,$order,$iscount=false) {

    $functionString='
        if ('.($iscount?'true':'false').'){
              if(count($a["'.$sortField.'"]) > count($b["'.$sortField.'"])) return 1*'.$order.';
            if(count($a["'.$sortField.'"]) < count($b["'.$sortField.'"])) return -1*'.$order.';
          }else{
            if($a["'.$sortField.'"] > $b["'.$sortField.'"]) return 1*'.$order.';
            if($a["'.$sortField.'"] < $b["'.$sortField.'"]) return -1*'.$order.';
          }
        return 0;';

    usort($array2sort, create_function('$a,$b',$functionString));
    return $array2sort;
}
$testArray = array(
    array('name' => 'Lenny', 'note' => 5, 'listId' => array(654,987,32165)),
    array('name' => 'Olivier', 'note' =>3, 'listId' => array(2)),
    array('name' => 'Gregory', 'note' => 1, 'listId' => array(45,58)),
    array('name' => 'Clement', 'note' => 2, 'listId' => array(584,587,741,14781,147))
);


 function br($var_name,$param){
     static $style;
     if(!isset($style)){
         echo $style = '<style type="text/css">.big{font-family: Consolas}</style>';
     }
    echo "<pre class='big'>";
    if(is_array($param)){
        echo $var_name."<br>";
        print_r($param);
    }elseif (is_object($param)){
        print_r($param);
    }else{
        echo($var_name.' : '.$param);
    }
    echo "</pre>";
    echo '<hr>';
}

br('',(int) ((0.1+0.7) * 10 )); // 显示 7!
br('','ddddd对方答复');


$ipString = '192.168.1.1';
$ipArr = explode('.', $ipString);
$ipVal = ($ipArr[0] << 24)
    + ($ipArr[1] << 16)
    + ($ipArr[2] << 8)
    + $ipArr[3]
;

br('',$ipVal);